package main

import (
	"context"
	"github.com/PedroGao/go-advanced-tutorial/rpc/person"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	"net"
)

type greeter struct{}

func (s greeter) SayHello(ctx context.Context, req *person.HelloRequest) (*person.HelloReply, error) {
	return &person.HelloReply{
		Message: "hello " + req.Name,
	}, nil
}

func main() {
	listener, err := net.Listen("tcp", ":3000")
	if err != nil {
		panic(err)
	}
	s := grpc.NewServer()

	person.RegisterGreeterServer(s, &greeter{})
	reflection.Register(s)
	err = s.Serve(listener)
	if err != nil {
		panic(err)
	}
}
